#include<bits/stdc++.h>
using namespace std;
void solve(){
    long double tx1,ty1,tx2,ty2;
    cin>>tx1>>ty1>>tx2>>ty2;
    long double ax1,ay1,ax2,ay2;
    cin>>ax1>>ay1>>ax2>>ay2;
    long double k1 = 1.0l*(ty2 - ty1)/(tx2 - tx1);
    long double k2 = 1.0l*(ay2 - ay1)/(ax2 - ax1);
    long double b = 1.0l/sqrtl(abs(1 + k1*k1)),d = k1/sqrtl(abs(1 + k1*k1));
    long double f = 1.0l/sqrtl(abs(1 + k2*k2)),h = k2/sqrtl(abs(1 + k2*k2));
    long double tmax = min(sqrtl(abs((tx2 - tx1)*(tx2 - tx1) + (ty2 - ty1)*(ty2 - ty1))),sqrtl(abs((ax2 - ax1)*(ax2 - ax1) + (ay2 - ay1)*(ay2 - ay1))));
    long double fa = (b - f)*(b - f) + (h - d)*(h - d);
    long double fb = 2.0l*(tx1 - ax1)*(b - f) + 2.0l*(ty1 - ay1)*(h - d);
    long double fc = (tx1 - ax1)*(tx1 - ax1) + (ty1 - ay1)*(ty1 - ay1);
    long double ans = min(fc,tmax*tmax*fa + tmax*fb + fc);
    long double ct = -fb/2*fa;
    if(0 <= ct && ct <= tmax){
        ans = min(ans,ct*ct*fa + ct*fb + fc);
    }
    cout<<fixed<<setprecision(10)<<sqrtl(ans)<<'\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        solve();
    }
}
